package ppos2.kmlgenerator;

import java.util.ArrayList;

public class GPSdevice {

	private double baseLatitude = 56.144;
	private double baseLongitude = 10.199;
	
	private ArrayList<GPSreading> coordinates;
	
	private String csvCollection = new String();
	
	public String generateCSVcollection()
	{
		for(int i = 0; i<coordinates.size();i++)
		{
			csvCollection = csvCollection + coordinates.get(i).generateCSVentry();
		}
		
		// Remove the last comma...
		this.csvCollection = this.csvCollection.substring(0, csvCollection.length()-1);
		
		return this.csvCollection;
	}
	
	public void initializeReadings(int numReadings)
	{
		coordinates.add(0, new GPSreading(baseLongitude, baseLatitude, 0));
		
		for (int i = 0; i< numReadings; i++)
		{
			generateNext(0.0002);
		}
	}

	@Override
	public String toString() {
		return coordinates.toString();
	}

	public String getCsvCollection() {
		return csvCollection;
	}

	public void generateNext(double step) {
		coordinates.add(coordinates.size(), new GPSreading(coordinates.get(coordinates.size()-1).getLongitude()+step,
				coordinates.get(coordinates.size()-1).getLatitude()+step, 0));
	}

	public GPSdevice(double baseLatitude, double baseLongitude) {
		super();
		this.baseLatitude = baseLatitude;
		this.baseLongitude = baseLongitude;
		this.coordinates = new ArrayList<GPSreading>();

	}

	public double getBaseLatitude() {
		return baseLatitude;
	}

	public void setBaseLatitude(double baseLatitude) {
		this.baseLatitude = baseLatitude;
	}

	public double getBaseLongitude() {
		return baseLongitude;
	}

	public void setBaseLongitude(double baseLongitude) {
		this.baseLongitude = baseLongitude;
	}

	public ArrayList<GPSreading> getCoordinates() {
		return coordinates;
	}

	public void setCoordinates(ArrayList<GPSreading> coordinates) {
		this.coordinates = coordinates;
	}



}
